package org.mspring.platform.api.rss.elements;

import electric.xml.Document;
import electric.xml.Element;
import electric.xml.ParseException;

import java.io.BufferedReader;
import java.io.Reader;
import java.util.List;

/**
 * 
 * @author Gao Youbo
 * @since 2013年7月26日
 */
@SuppressWarnings({ "rawtypes" })
public class RSSReader {
    protected Reader in = null;
    protected Channel channel = null;
    Element root = null;

    public RSSReader(Reader paramReader) throws ParseException {
        setReader(paramReader);
    }

    public RSSReader() {
    }

    public Channel getChannel() {
        return this.channel;
    }

    public void setReader(Reader paramReader) throws ParseException {
        Object localObject = paramReader;
        if (!paramReader.markSupported())
            localObject = new BufferedReader(paramReader);
        this.in = ((Reader) localObject);
        parseInput();
    }

    protected void parseInput() throws ParseException {
        Document localDocument = new Document(this.in);
        this.channel = new Channel();
        this.root = localDocument.getRoot();
        this.channel = Channel.getChannel(this.root);
        Image localImage = Image.getImage(this.root);
        if (localImage != null)
            this.channel.setImage(localImage);
        TextInput localTextInput = TextInput.getTextInput(this.root);
        if (localTextInput != null)
            this.channel.setTextInput(localTextInput);
        List localList = Item.getItems(this.root);
        if (localList != null)
            this.channel.setItems(localList);
    }
}